package com.dgut.controller;

import com.dgut.result.Result;
import com.dgut.service.TurnoverService;
import com.dgut.vo.IndividualSalesVO;
import com.dgut.vo.TurnoverVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@Api(tags = "营业额管理接口")
@Slf4j
@RequestMapping("/turnover")
public class TurnoverController {
    @Autowired
    private TurnoverService turnoverService;

    /**
     * 营业额查询
     *
     * @param startDate
     * @param endDate
     * @return
     */
    @GetMapping
    @ApiOperation("营业额查询")
    public Result getTurnover(@RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
                              @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
        log.info("营业额查询，开始时间：{}，结束时间：{}", startDate, endDate);
        TurnoverVO turnover = turnoverService.getTurnover(startDate, endDate);
        return Result.success(turnover);
    }

    @GetMapping("/emp")
    @ApiOperation("根据销售人员查询营业额")
    public Result getTurnoverByEmpId(Long empId,
                                     @RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
                                     @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {
        log.info("根据销售人员查询营业额，销售人员id：{}，开始时间：{}，结束时间：{}", empId, startDate, endDate);

        IndividualSalesVO individualSalesVO = turnoverService.getTurnoverByEmpId(empId, startDate, endDate);
        return Result.success(individualSalesVO);
    }

}
